<{include file="top.html" }>
</head>
<body>
<div class="xy-panel">
    <div class="xy-panel-top">
        <div class="xy-titlebar">
            <div class="xy-titlebar-left">
                <a class="insertBefore_left_arrow_gray" href="javascript:void(0);"></a>
            </div>
            <div class="xy-titlebar-title">找回密码</div>
            <div class="xy-titlebar-right"></div>
        </div>
    </div>
    <div class="xy-panel-content" style="bottom:0;">
        <div class="xy-row vDirectionRow">
            <form class="form-box">
                <dl><input type="tel" id="phone" placeholder="请输入手机号"></dl>
                <dl>
                    <input type="tel" id="code" class="tele" placeholder="请输入手机验证码">
                    <a class="hqyz" href="javascript:void(0);">获取验证码</a>
                </dl>
                <dl><input type="password" id="password" placeholder="请输入新密码"></dl>
            </form>
            <div class="ui-button ui-button-2">
                <button id="sub">重置密码</button>
            </div>
        </div>
    </div>
</div>

<{include file="signBody.html"}>

</body>
</html>
<script src="<{$preStaticUrl}>Wap/js/flexible.js"></script>
<script>
    var registerUrl= "<{U('User/forgetPassword')}>";
    var smsUrl = "./api.php?m=api&c=Sms&a=sendSmsCode";
    var flag = 0;

    $(function(){

        $("#sub").on("click", function () {
            var phone = $("#phone").val()
                    ,code = $("#code").val()
                    ,password = $("#password").val();
            if (!validatePhone(phone)) {
                layer.msg('请填写正确的手机号码');
                return false;
            }
            if(code.length != 4){
                layer.msg("请填写正确的验证码");
                return false;
            }
            if(password.length < 6 || password.length > 32){
                layer.msg("密码格式不正确！支持6-32字节");
                return false;
            }

            $.getJSON(registerUrl, {phone:phone,code:code,password:password}, function(data){
                if(data.status) {
                    layer.msg(data.msg);
                }else{
                    layer.msg('修改成功！请重新登录');
                    window.history.go(-1);
                }
            });
        });

        $(".hqyz").on('click', function () {
            var phone = $("#phone").val();
            if (!validatePhone(phone)) {
                layer.msg('请输入正确的手机号码');
                return false;
            }
            $.getJSON(smsUrl, {phone:phone,bind:0}, function(data){
                layer.msg(data.msg);
                if(data.status == 0) {
                    flag = false;
                    $('.hqyz').html('<font>60</font>秒后获取');
                    timer = setInterval(countDown, 1000);
                }
            });
        });

        var timer;
        var flag = true;
        var countDown = function CountDown() {
            var maxtime = parseInt($(".hqyz font").html());
            if(maxtime>0){
                --maxtime;
                $('.hqyz font').html(maxtime);
            }else{
                clearInterval(timer);
                $('.hqyz').html('获取验证码');
                flag = true;
            }
        }


    });


</script>